package com.example.pixelyear.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.example.pixelyear.R
import com.example.pixelyear.bean.DateBean
import com.example.pixelyear.utils.UIUtils
import com.example.pixelyear.utils.Utils
import com.example.pixelyear.utils.extension.setOnDoubleClickListener
import com.example.pixelyear.utils.extension.setVisi
import kotlinx.android.synthetic.main.item_mood_line.view.*

class MoodLineAdapter(val context: Context) : BaseAdapter<DateBean>() {
    private val year = Utils.getYear()
    private val month = Utils.getMonth()
    private val day = Utils.getDay()
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BaseViewHolder {
        return BaseViewHolder(LayoutInflater.from(context).inflate(R.layout.item_mood_line, parent, false))
    }

    override fun onBindView(itemView: View, bean: DateBean, position: Int) {
        itemView.Item_MoodLine_Bottom.setVisi(position != size() - 1)
        itemView.Item_MoodLine_Mood.setTextColor(bean.color)
        itemView.Item_MoodLine_Mood.text = bean.mood
        itemView.Item_MoodLine_MoodText.text = bean.note
        itemView.Item_MoodLine_Date.text = "${bean.day} 号"
        if (bean.year == year && bean.month == month && bean.day == Utils.getDay()) {
            itemView.Item_MoodLine_NowDay.text = "今"
        } else itemView.Item_MoodLine_NowDay.text = ""
        itemView.setOnDoubleClickListener {
            onItemClick?.click(bean, position)
        }
    }

    override fun updateList(list: MutableList<DateBean>) {
        super.updateList(list)
    }
}
